package com.atguigu.hbase.util;

import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;


/**
 * @ClassName ConnectionUtils
 * @DeScription Hbase连接工具类
 * @Author 剧情再美终是戏
 * @Date 2019/12/7 13:38
 * @Version 1.0
 **/
public class ConnectionUtils {

    private ConnectionUtils() {
    }

    private static Logger logger = LoggerFactory.getLogger(ConnectionUtils.class);


    /**
     * 获取Hbase连接
     *
     * @param
     * @return org.apache.hadoop.hbase.client.Connection
     * @Author 剧情再美终是戏
     * @Date 2019/12/7
     * @Version 1.0
     **/
    public static Connection getConnection() throws IOException {
        Connection connection = ConnectionFactory.createConnection();
        if (null == connection) {
            logger.error("com.atguigu.hbase.util.ConnectionUtils.getConnection Happen Error : 获取Hbase连接失败！");
        }
        logger.debug("com.atguigu.hbase.util.ConnectionUtils.getConnectio success" + connection);
        return connection;
    }


    /**
     * 关闭Hbase连接
     *
     * @param conn
     * @return void
     * @Author 剧情再美终是戏
     * @Date 2019/12/7
     * @Version 1.0
     **/
    public static void close(Connection conn) throws IOException {
        if (null == conn) {
            return;
        }
        conn.close();
        logger.debug("com.atguigu.hbase.util.ConnectionUtils.close success");
    }

}
